package com.berwin.bmfb.views;

import com.berwin.bmfb.entity.BMFont;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public abstract class BasePanel extends JPanel implements DocumentListener, ChangeListener {

    protected MainView mainView;

    protected boolean isFromSelected = false;
    protected boolean giveUpListenValueChange = false;

    public BasePanel(MainView mainView) {
        this.mainView = mainView;
    }

    public abstract void onUpdate();

    public abstract void onSelectLetter(int idx);

    public abstract void onValueChanged();

    public abstract void onBMFontUpdated(BMFont bmFont);

    public void doLayoutChars() {
    }

    @Override
    public void stateChanged(ChangeEvent e) {
        if (!giveUpListenValueChange)
            this.onValueChanged();
    }

    @Override
    public void insertUpdate(DocumentEvent e) {
        if (!giveUpListenValueChange)
            this.onValueChanged();
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        if (!giveUpListenValueChange)
            this.onValueChanged();
    }

    @Override
    public void changedUpdate(DocumentEvent e) {

    }
}
